package com.ggy.tuibi.Schedu;

import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import javafx.concurrent.Task;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@EnableScheduling
@Component
@Slf4j
public class HuanLeMoGuiChengSchedu {

   static List<String> accountList = new ArrayList<>();

    static {
        accountList.add("12690");
        accountList.add("22849");
        accountList.add("22890");
        accountList.add("22891");
    }

    @Scheduled(cron = "0 25 2 * * ?")
    public void threadSignNo() {
        log.info("开始签到欢乐魔鬼城");
        ExecutorService executorService = Executors.newCachedThreadPool();


        for (String account : accountList) {
            List<Runnable> taskList = new ArrayList<>();
            for (int i = 0; i < 300; i++) {
                taskList.add(() -> {
                    signNO(account);
                });
            }
            for (Runnable runnable : taskList) {
                executorService.submit(runnable);
            }
            try {
                Thread.sleep(60000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }finally {
                taskList.clear();
            }
        }

        executorService.shutdown();
    }

    public static void main(String[] args) {
        HuanLeMoGuiChengSchedu service = new HuanLeMoGuiChengSchedu();
        ExecutorService executorService = Executors.newCachedThreadPool();
        List<Runnable> taskList = new ArrayList<>();
        for (int i = 0; i < 300; i++) {
            taskList.add(() -> service.xiaji());
        }
        for (Runnable runnable : taskList) {
            executorService.submit(runnable);
        }

        executorService.shutdown();
    }

    private void email() {

    }

    private void xiaji() {
        Map<String, Object> bodyMap = new HashMap<>();
        bodyMap.put("machine_position", "8");
        bodyMap.put("machine_types", "11");
        bodyMap.put("user_code", "1172040");
        bodyMap.put("user_id", "tqdgRUb_3hcUCUpRI70jkRuhKCB7ohYh");
        bodyMap.put("machine_alias", "o5hNquYFaYohJR2Y6COgKA");
        bodyMap.put("machine_id", "20240521072059501");
        bodyMap.put("IMEI", "98d2b146505b4708ab5253ea35151e7a");
        bodyMap.put("message", "9");
        HttpResponse response = HttpUtil.createPost("http://www.douyuewang.com/YuanQiJieJi_Web/doll_WanShengYe.do?mapStr=" + JSONUtil.toJsonStr(bodyMap)).execute();
        System.out.println(response.body());
    }


//    @Scheduled(cron = "0 25 11 * * ?")
    public void festival() {
        ExecutorService executorService = Executors.newCachedThreadPool();
        for (String usercode : accountList) {
            List<Runnable> taskList = new ArrayList<>();
            for (int i = 0; i < 300; i++) {
                taskList.add(()->festivalSignNo(usercode));
            }
            for (Runnable runnable : taskList) {
                executorService.submit(runnable);
            }
            try {
                Thread.sleep(60000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }finally {
                taskList.clear();
            }
        }

        executorService.shutdown();
    }

    public void signNO(String account) {
        String signNoUrl = "http://hlwsy.feiying24.com/HappyMoGuiCheng_Web/userIndex_updateUser_signin.do?user_id=" + account + "&reward_id=7.0&cumulative_id=7.0";
        HttpResponse response = HttpUtil.createPost(signNoUrl).execute();
        log.info("签到响应:{}", response.body());
    }

    public void festivalSignNo(String userCode) {
        Map<String, Object> param = new HashMap<>();
        param.put("user_code", userCode);
        String festivalUrl = "http://hlwsy.feiying24.com/HappyMoGuiCheng_Web/activity_updateDoubleRites.do?phoneSys=WEB&mapStr=" + JSONUtil.toJsonStr(param);
        HttpResponse response = HttpUtil.createPost(festivalUrl).execute();
        log.info("提交节假日礼包响应:{}", response.body());
    }
}
